Return to doc.sitecore.com

Automatically save changes in RTE
Prev Next

Author: Alexey Romaniuha
Posted: 7/3/2007 3:37:09 PM

Question: is it possible to make Rich Text Editor save all changes instead of discarding them when user exits RTE without pressing Discard button?

 

Version: 5.3.1 rev. 070515

 

Solution:

  1. Go to /sitecore/shell/Controls/Rich Text Editor/Default.html file.
  2. Find <body> tag and make it look like this:

<body style="overflow:auto;width:100%;height:100%" onunload="javascript: OnUnload();">

  1. Add following function to <script> section of a file:

      function OnUnload() {
        var form = scGetForm();
        form.postEvent("", "", "custom:unload");
      }

  1. Create an extension class that implements the following behavior:

namespace Sitecore.Custom
{
    public class CustomRichTextEditorForm : Sitecore.Shell.Applications.ContentManager.RichText.RichTextEditorForm
    {
        public override void HandleMessage(Sitecore.Web.UI.Sheer.Message message)
        {
            base.HandleMessage(message);
            if (message.Name == "custom:unload")
            {
                if (System.Web.HttpContext.Current.Session["BUTTON_USED"] != null &&
                    (bool)System.Web.HttpContext.Current.Session["BUTTON_USED"] == false)
                {
                    base.Accept_Click();
                }
                System.Web.HttpContext.Current.Session["BUTTON_USED"] = false;
            }
        }

        protected new void Accept_Click()
        {
            base.Accept_Click();
            System.Web.HttpContext.Current.Session["BUTTON_USED"] = true;
        }

        protected new void Reject_Click()
        {
            base.Reject_Click();
            System.Web.HttpContext.Current.Session["BUTTON_USED"] = true;
        }

  1. Compile an assembly and place it into /bin folder.
  2. Copy /sitecore/shell/Applications/Content Manager/RichText/Rich Text Editor.xml file to /sitecore/shell/override folder.
  3. Replace

      <CodeBeside Type="Sitecore.Shell.Applications.ContentManager.RichText.RichTextEditorForm,Sitecore.Client"/>

with your class declaration, e.g.:

      <CodeBeside Type="Sitecore.Custom.CustomRichTextEditorForm,Sitecore.Custom"/>


Prev Next